#include <iostream>
#include <functional>
#include <thread>
#include <atomic>
#include <cmath>
#include <chrono> 
#include <cstdlib>
#include <mutex>
#include <condition_variable>
#include <chrono>
#include <cstdlib>


//C++11创建线程的基本思路
//1.直接带参数构造，创建可执行线程
//2.先创建空线程对象，通过移动构造或者赋值来转移对象。


std::mutex g_mutex;

void Print()
{
    std::lock_guard lkd(g_mutex);
    std::cout<<"Thread ID:" <<std::this_thread::get_id()<<"  "<<"this is a test "<<"\n";
}

int main()
{
    //移动赋值
    // std::vector<std::thread> t_arr(10);
    // for(auto & td:t_arr)
    // {
    //     td = std::thread(Print);
    // }


    //移动构造
    std::vector<std::thread> t_arr;
    for(int i = 0;i<10;i++)
    {
        t_arr.push_back(std::thread(Print));
    }
    for(auto & td:t_arr)
    {
        td.join();
    }
    return 0;
}